from django.db import models
# 用户表‌
class User(models.Model):
    # 用户名(varchar)
    username=models.CharField(max_length=50)
    # 密码(varchar)
    password=models.CharField(max_length=50)
    # 身份标识(0学生/1管理员)
    power=models.IntegerField(choices=[(0,"学生"),(1,"管理员")])

# 设备分类表‌
class SheBeiFenLei(models.Model):
    # 分类名称(varchar50)
    flname=models.CharField(max_length=50)
    # 父分类ID(自关联外键)
    fufenleiId=models.ForeignKey('self',null=True,on_delete=models.SET_NULL,related_name='aa')
    # 创建时间(datetime)
    createtime=models.DateTimeField(auto_now_add=True)

# 设备信息表‌
class SheBeiXinXi(models.Model):
    # 设备名称(varchar)
    shebeiname=models.CharField(max_length=50)
    # 资产编号(unique varchar)
    cichanbianhao=models.CharField(max_length=50,unique=True)
    # 分类ID(外键)
    fenleiId=models.ForeignKey(SheBeiFenLei,on_delete=models.CASCADE,related_name='SheBeiFenLei')
    # 购置价格(decimal(10,2))
    gzpprice=models.DecimalField(max_digits=10,decimal_places=2)
    # 库存量(integer)
    num=models.IntegerField()
    # 状态(0正常/1维修/2报废)
    status=models.IntegerField(choices=[(0,"正常"),(1,"维修"),(2,"报废")])

# 借用记录表‌
class JieYongJiLu(models.Model):
    # 设备ID(外键)
    shebeiId=models.ForeignKey(SheBeiXinXi,on_delete=models.CASCADE,related_name='SheBeiXinXi')
    # 借用数量(integer)
    jieyongNum=models.IntegerField()
    # 借用人(varchar)
    jieyongren=models.CharField(max_length=50)
    # 借用日期(datetime)
    jieyongtime=models.DateTimeField(auto_now_add=True)
    # 预计归还日期(datetime)
    yjghtime=models.DateTimeField(auto_now_add=True)
    # 实际归还日期(datetime,null)
    sjghtime=models.DateTimeField(auto_now_add=True,null=True)






# Create your models here.
